package com.example.newinfinity.IconModel

import android.content.Context
import android.util.AttributeSet
import android.view.Gravity
import androidx.core.view.setPadding
import com.example.newinfinity.R
import io.github.florent37.shapeofview.ShapeOfView
import io.github.florent37.shapeofview.shapes.CircleView

//包裹IconTextView 裁切icon图标为圆形,
class CircleIconTextView(context: Context, attrs: AttributeSet? = null) :
    CircleView(context, attrs) {
    //创建icon图标的基础显示
    private var iconTextView: IconTextView? = null
    //中转IconTextView中icon被点击的信息给IconMenu
    var clickCallback:(IconTextView) -> Unit = {}
        set(value) {
            field = value
            iconTextView?.clickCallback = value
        }

    init {
        iconTextView = IconTextView(context, attrs)

        val lp = LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)
        lp.gravity = Gravity.CENTER
        addView(iconTextView,lp)
    }

    fun bindIconModel(iconModel:IconModel){
        iconTextView!!.bindIconModel(iconModel)
        if (iconModel.iconModelType == IconModelType.DRAW_MENU){
            iconTextView!!.setIconSize(30,25)
        }else{
            iconTextView!!.setIconSize(20,28)
        }
    }
}